/**
 * File: protocol.h
 * Brief:
 * Created by: zhangping
 * Created at: 2017.06.5
 * Modified by:
 * Modified at:
 **/
 
#ifndef _MY_PROTOCOL_H_
#define _MY_PROTOCOL_H_


enum InsEnum{
  kVelMode=0,  // Work at Velocity model
  kPosMode=1   // Work at Position model
};


typedef unsigned char U8;

/** Institution protocol format*/
struct InsProtocol{
  U8 header1;
  U8 header2;
  U8 mode;
  U8 x[2];
  U8 y[2];
  U8 z[2];
  U8 orientation;
};

/** Instruction data*/
static const struct InsProtocol kInsProtocol[]={
  { 0xff,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // Velocity mode
  { 0xff,0xfe,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // Position mode
};


/** Sensor data */
/** Ultrasonic data */
struct UltrasonicData{
  U8 header;
  U8 type;
  U8 range;	 // distance
  U8 angle;  //
  U8 end;
};

/** Gyroscope data */
struct GyroscopeData{
  U8 header;
  U8 type;
  U8 h_x;  // High 8bit for x-axis.
  U8 l_x;  // Low 8bit for x-axis.
  U8 h_y;
  U8 l_y;
  U8 h_z;
  U8 l_z;
  U8 h_av; // High 8bit for angular velocity.
  U8 l_av; // Low 8bit for angular velocity.
  U8 end;
};

/** Position data */
struct PositionData{
  U8 header;
  U8 type;
  U8 sensor_id;
  U8 x;
  U8 y;
  U8 z;
  U8 end;
};

/** union for Sensor data */
union SensorData{
  UltrasonicData ult;
  GyroscopeData gyro;
  PositionData pos;
};

/** Sensor initial data */
static const UltrasonicData kUltrData = { 0xff, 0x01,
                                          0x00, 0x00,
                                          0xfe};
static const GyroscopeData kGyroData = { 0xff, 0x02,
                                         0x00, 0x00,
                                         0x00, 0x00,
                                         0x00, 0x00,
                                         0x00, 0x00,
                                         0xfe};
static const PositionData kPosData={ 0xff, 0x03,
                                     0x00, 0x00, 0x00,
                                     0xfe};

#endif
